//index.js
//获取应用实例
const app = getApp()
var ipUrl=app.globalData.ipUrl;
var that;
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    activeName: 'a',
    active:0,
    array:[],//接收结果的数组
    sum:0,//总条数
    score:0,//总比例评分
    page:1,//页数
    rows:10,//每页条数
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  viewopen(){
    wx.navigateTo({
      url: '../viewopen/index'
    })
  },
  /**
  * 页面上拉触底事件的处理函数
  */
 onReachBottom: function () {
   if (this.data.page <= this.data.total){
     this.getDoctorData();
   }
 },
  getDoctorData: function () {
    var page = that.data.page + 1;
    var rows = that.data.rows;
    wx.request({
      url: ipUrl+'/comment/comment/selectall2?page='+that.data.page+'&limit='+that.data.rows+'&tid=1', //向后台发请求
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var sum=0;
        var score=0;
      for(var i=0;i<res.data.length;i++){
        sum+=i;
        score+=res.data[i].score;
      }
      var arrays=res.data
      var csore=csore/sum
      that.setData({
        csore:csore,
        array:arrays,
        sum:sum
      })
      }
    })
   },
  onLoad: function () {
    that=this;
    that.setData({ 
      ipUrl: ipUrl
     });
     wx.request({
      url: ipUrl+'/comment/comment/selectall2?page='+that.data.page+'&limit='+that.data.rows+'&tid=6', //向后台发请求
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var sum=1;
        var score=0;
      for(var i=0;i<res.data.length;i++){
        sum+=i;
        score+=res.data[i].score;
      }
      var pf=score/sum
      that.setData({
        score:pf,//总比例评分
        array:res.data,
        sum:sum
      })
      }
    });
     wx.request({
      url: ipUrl+'/teacherdetails/teacherdetails/selectByIdTeacher?tid='+6, //仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data)
        that.setData({
          teacherdeatils:res.data
        });
      },
      fail(e){
        console.log("失败")
      }
    })
  }



})